package com.hr.LandR.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hr.common.annotation.Log;
import com.hr.common.core.controller.BaseController;
import com.hr.common.core.domain.AjaxResult;
import com.hr.common.enums.BusinessType;
import com.hr.LandR.domain.LeadershipRelationship;
import com.hr.LandR.service.ILeadershipRelationshipService;
import com.hr.common.core.page.TableDataInfo;

/**
 * 负责人关系表Controller
 * 
 * @author guan
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/manage/LandR")
public class LeadershipRelationshipController extends BaseController
{
    @Autowired
    private ILeadershipRelationshipService leadershipRelationshipService;

    /**
     * 查询负责人关系表列表
     */
    @PreAuthorize("@ss.hasPermi('manage:LandR:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeadershipRelationship leadershipRelationship)
    {
        startPage();
        List<LeadershipRelationship> list = leadershipRelationshipService.selectLeadershipRelationshipList(leadershipRelationship);
        return getDataTable(list);
    }

    /**
     * 获取负责人关系表详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:LandR:query')")
    @GetMapping(value = "/{useridSubordinate}")
    public AjaxResult getInfo(@PathVariable("useridSubordinate") Long useridSubordinate)
    {
        return success(leadershipRelationshipService.selectLeadershipRelationshipByUseridSubordinate(useridSubordinate));
    }

    /**
     * 新增负责人关系表
     */
    @PreAuthorize("@ss.hasPermi('manage:LandR:add')")
    @Log(title = "负责人关系表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeadershipRelationship leadershipRelationship)
    {
        return toAjax(leadershipRelationshipService.insertLeadershipRelationship(leadershipRelationship));
    }

    /**
     * 删除负责人关系表
     */
    @PreAuthorize("@ss.hasPermi('manage:LandR:remove')")
    @Log(title = "负责人关系表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{useridSubordinates}")
    public AjaxResult remove(@PathVariable Long[] useridSubordinates)
    {
        return toAjax(leadershipRelationshipService.deleteLeadershipRelationshipByUseridSubordinates(useridSubordinates));
    }

    /**
     * 查询员工上下级
     */
    @PreAuthorize("@ss.hasPermi('manage:LandR:show')")
    @GetMapping(value = "/show/{id}")
    public AjaxResult show(@PathVariable("id") Long userId)
    {
        return success(leadershipRelationshipService.showLeadershipRelationship(userId));
    }
}
